package com.ftg.learn.chapter08;


import java.util.*;
import java.util.stream.Stream;

/**
 * @author kangjx
 * @createTime 2022/7/6
 */
public class LearnMap {

    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : n + 1;
    }
    public static void main(String[] args) {
        int n = 3 - 1 >> 1;
//        System.out.println(Integer.toBinaryString(n));
//        System.out.println(Integer.toBinaryString(2));

        //把 学生基本信息存储起来  :  学号  姓名  年龄   性别  (1)
//
//        //你和你同桌子 list<map>
//        Map<String,Object> stu = new HashMap<>();
//        stu.put("学号",1001);
//        stu.put("姓名","张三");
//        stu.put("年龄",23);
//
//        Map<String,Object> stu1 = new HashMap<>();
//        stu1.put("学号",1002);
//        stu1.put("姓名","张三1");
//        stu1.put("年龄",24);
//
//        List<Map<String,Object>> stus = new ArrayList<>();
//        stus.add(stu);
//        stus.add(stu1);
//        System.out.println(stus);
//
//        for(Map<String,Object> map : stus){
//            System.out.println(map.get("姓名"));
//        }
//        //表示不重复个数
//        int diff_no = 2;
//        Map<Integer,String> nums = new HashMap<>(2);
//        while (nums.size() < diff_no){
//            int a = (int)(Math.random() * 3) + 1;
//            nums.put(a,null);
//            System.out.println("-->");
//        }
//        System.out.println(nums);
//        //hash冲突 jdk1.6 hashmap 数组(冲突) jdk1.7 数组+链表 jdk1.8  数组+链表 + 快速结构(red/black tree)
//        String a = "Aa";
//        String b = "BB";
//        System.out.println(a.hashCode());
//        System.out.println(b.hashCode());
//
//        //1
//
//        long t = Arrays.stream(as).distinct().count();
//        System.out.println(t);

//        LearnMap l = new LearnMap();
//        System.out.println(l.pringDistinctFor6());
        System.out.println("abc".hashCode());
        int n1 = 96354;
        System.out.println("abcdrfeasfldsjfksdjkl".hashCode());
        int n2 =2043047169;
        System.out.println(n1 >>> 16);
        int n11 = 1;
        System.out.println(n2 >>> 16);
        int n21 = 31174;

        System.out.println(n1 ^ n11);
        System.out.println(n2 ^ n21);
        System.out.println(7 & 16);
    }

    static final int myhash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

    public long countDistinctNum(int num){
        char[] as = createBuild(num);
        Stream.Builder b = Stream.builder();

        for(int i = 0 ;i < as.length;i++){
            b.add(as[i]);
        }
        return  b.build().distinct().count();
    }

    public char[] createBuild(int num){
        String str = String.valueOf(num);
        char[] as = str.toCharArray();
        return as;
    }

    public List<Integer> pringDistinctFor6(){
        List<Integer> list = new ArrayList<>();
        int start = 102345;
        int end = 159787;
        int max = 999999;
        for(int i = start;i < end;i++){
            if(countDistinctNum(i) != 6){
                continue;
            }else{
                int sum = i  * 6;
                char[] old = createBuild(i);
                Arrays.sort(old);
                char[] news = createBuild(sum);
                Arrays.sort(news);
                if(sum < max && countDistinctNum(sum) == 6 && Arrays.equals(old,news)){
                    list.add(i);
                }
            }
        }
        return list;
    }


}
